<?php

namespace app\api\controller;

use app\api\validate\User;
use app\BaseController;
use think\exception\ValidateException;

class Sms extends BaseController
{

    public function code()
    {
        $phoneNumber = input('param.phone_number', '', 'trim');

        $data = [
            'phone_number' => $phoneNumber
        ];
        try {
            validate(User::class)->scene("send_code")->check($data);
        } catch (ValidateException $e) {
            return show(config("status.error"), $e->getError());
        }

        //调用business层的数据
        if (\app\common\business\Sms::sendCode($phoneNumber, 6, 'ali')) {
            return show(config("status.success"), "发送验证码成功");
        }

        return show(config("status.error", "发送验证码失败"));
    }
}